    //
//  GraphSetup.m
//  iStock Global
//
//  Created by Andy on 2010/11/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "GraphSetup.h"
#import "DBHelper.h"
#import "AppDelegate.h"
#import "ExchangeClass.h"
@implementation GraphSetup
@synthesize delegate;
@synthesize name;
@synthesize code;
@synthesize delegate_UIPopoverController;
@synthesize barbuttonitem;
@synthesize AppleDeglate;
#pragma mark -
#pragma mark  初始化

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
-(id)initWithTargetSymbol:(DataObject *)adataobject {
	
    self= [super init];
	if (self ) {
		
		
		stockdata=adataobject;
		
		
	}
	return self;	 	
}
- (void)loadView {
	if (stockdata==nil) {
        NSLog(@"nil");
    }
    else{
        NSLog(@"not nil");
    
    }
      
    
    
	UIView *mainview;
	mainview=[[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
	self.view=mainview;
    [mainview release];
	self.view.backgroundColor=[UIColor lightTextColor];	
	UINavigationBar *nav;
	
	nav = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];	
	
	UIBarButtonItem *barButton ;
	barButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done",@"完成")  style:UIBarButtonItemStylePlain target:self action:@selector(slideOut)];
	
    UINavigationItem *item;
	
    
  
	  
    //標記:是否移除交易所碼        
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
    
    if ([[prefs objectForKey:@"isRemoveExchangeCode"] boolValue]==YES) {
        //字串分割
        NSArray *code_exchange_Array = [stockdata.symbol componentsSeparatedByString:@"."];
        if ([code_exchange_Array count]==2) {
            
            //lba.text=[NSString stringWithFormat:@"%@ (%0.0f/%i)", [code_exchange_Array objectAtIndex:0],amountDone,progresscount];        
             item = [[UINavigationItem alloc] initWithTitle:[[code_exchange_Array objectAtIndex:0] stringByAppendingString:NSLocalizedString(@" Data Indicator","  指標設定")] ];       
        }
        else{
             item = [[UINavigationItem alloc] initWithTitle:[stockdata.symbol stringByAppendingString:NSLocalizedString(@" Data Indicator","  指標設定")] ];
            
        }
        
    }
    else {
         item = [[UINavigationItem alloc] initWithTitle:[stockdata.symbol stringByAppendingString:NSLocalizedString(@" Data Indicator","  指標設定")] ];
    }                   
    
    
    
    [item setRightBarButtonItem: barButton];
    [barButton release];
	[nav pushNavigationItem:item animated:NO];	
	[item release];
	
	//UIBarButtonItem *rightButton =[[UIBarButtonItem alloc] initWithTitle:@"GoBack" style:UIBarButtonItemStyleDone target:self action:@selector(slideOut)];
	
	myTable = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 48.0f, 320.0f, self.view.frame.size.height)  style:UITableViewStyleGrouped];
	
	NSString *historyrecord;
	historyrecord=NSLocalizedString(@"History Data Records( ",@"歷史價格明細( ");
	historyrecord= [historyrecord  stringByAppendingFormat:@"%i",[stockdata.financialData count] ];	
	historyrecord=[historyrecord stringByAppendingString:NSLocalizedString(@" )",nil)];
	
	StockInformation_0 = [[NSArray arrayWithObjects:historyrecord,nil] retain];	
	
    //標記:判斷是MESA或LF
    NSString *DisplayName;
    DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
    NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];    
    
    if ([DisplayName_array count]>=3) {
        if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
            //MESA
            TechIndicator_1 = [[NSArray arrayWithObjects:
                                NSLocalizedString(@"Show Indicator Data",@"顯式指標資料"),
                                NSLocalizedString(@"MESA",@"MESA"),
                                NSLocalizedString(@"Moving Average",@"移動均線"),
                                NSLocalizedString(@"KD Indicator", @"KD指標"),
                                NSLocalizedString(@"Volume", @"成交量"),
                                
                                nil] retain];          
            
            
        }
        else{
            //開始LF
            TechIndicator_1 = [[NSArray arrayWithObjects:
                                NSLocalizedString(@"Show Indicator Data",@"顯式指標資料"),
                                NSLocalizedString(@"Dynamic Stops Line", @"動態停損利線"),						
                                NSLocalizedString(@"Moving Average",@"移動均線"),
                                NSLocalizedString(@"KD Indicator", @"KD指標"),
                                NSLocalizedString(@"Volume", @"成交量"),
                                
                                nil] retain];
            
            
        }
    }
    
    
    
    
   	
	TradeSystem_2  = [[NSArray arrayWithObjects:
					   NSLocalizedString(@"Dynamic Stops Line Setup",@"動態停損利線設定") ,
					   NSLocalizedString(@"Dynamic Stops Line Report",@"動態停損利線報告"),
					   @"程式交易最佳化",
					   @"程式交易最佳化設定",
					   nil] retain];
	
	myTable.dataSource = self;	//連結資料 UITableViewDataSource
	myTable.delegate=self; //連結動作 UITableViewDelegate	
	[self.view addSubview:myTable];
	[myTable release];
	//[self.view addSubview:headerbutton];
	[mainview addSubview:nav ];	
	[nav release];
}

#pragma mark -
#pragma mark  表格

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
	if ([[prefs objectForKey:@"isManager"] boolValue]==YES) {
		return 3;
	}
	else {
		return 2;
	}

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
	switch (section) {
		case 0:
			return [StockInformation_0 count];
			break;
		case 1:{
			/*
            NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
			if ([[prefs objectForKey:@"isManager"] boolValue]==YES) {
				return [TechIndicator_1 count];
			}
			else {
				return [TechIndicator_1 count]-1; //最後一各mesa 不顯式
			}			
			*/
			return [TechIndicator_1 count];			
			break;
		
		}
		case 2:
			return [TradeSystem_2 count];
			break;
	} 
	return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	static NSString *CellIdentifier = @"TableCellAddStockWatchList";	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
									   reuseIdentifier:CellIdentifier] autorelease];
	}
	switch (indexPath.section) {
		case 0:{
			cell.textLabel.text = [StockInformation_0 objectAtIndex:indexPath.row];
			
			break;}
		case 1:{
			//技術指標區域
			
			cell.textLabel.text = [TechIndicator_1 objectAtIndex:indexPath.row];
		    if ([cell.textLabel.text isEqualToString:NSLocalizedString(@"Show Indicator Data",@"顯式指標資料")]) {
			//顯式數值資料
				//讓表格的列不會被使用者點選時出現藍色的狀態
				cell.selectionStyle=UITableViewCellSelectionStyleNone;				
				
				//開關
				UISwitch *onoff;
				onoff = [[UISwitch alloc] initWithFrame: CGRectZero];
				onoff.tag=100;  
				[onoff addTarget: self action: @selector(switchChange:) forControlEvents: UIControlEventValueChanged];
				
				NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
				onoff.on=[(NSNumber *)[prefs objectForKey:@"isSowIndicatorNumber"] boolValue];
				
				[self.view addSubview: onoff];
				cell.accessoryView=onoff;
				[onoff autorelease];				
				
				
			}
			 		
			
			
			break;}
		case 2: {
			cell.textLabel.text = [TradeSystem_2 objectAtIndex:indexPath.row];
	        break;}
		 
	}
	NSString *historyrecord;
	historyrecord=NSLocalizedString(@"History Data Records( ",@"歷史價格明細( ");
	historyrecord= [historyrecord  stringByAppendingFormat:@"%i",[stockdata.financialData count] ];	
	historyrecord=[historyrecord stringByAppendingString:NSLocalizedString(@" )",nil)];	
	
	if ([cell.textLabel.text isEqualToString:NSLocalizedString(@"Dynamic Stops Line", @"動態停損利線")] 
		|| [cell.textLabel.text isEqualToString:NSLocalizedString(@"MESA",@"MESA")] 
		|| [cell.textLabel.text isEqualToString:NSLocalizedString(@"Moving Average",@"移動均線")] 
		|| [cell.textLabel.text isEqualToString:NSLocalizedString(@"KD Indicator", @"KD指標")] 
		|| [cell.textLabel.text isEqualToString:NSLocalizedString(@"Volume", @"成交量")] 
		|| [cell.textLabel.text isEqualToString:@"程式交易最佳化設定"]				
		|| [cell.textLabel.text isEqualToString:NSLocalizedString(@"Dynamic Stops Line Setup",@"動態停損利線設定")] 
		|| [cell.textLabel.text isEqualToString:NSLocalizedString(@"Dynamic Stops Line Report",@"動態停損利線報告")] 		
		|| [cell.textLabel.text isEqualToString:NSLocalizedString(@"Show Indicator Data",nil)]		
		|| [cell.textLabel.text isEqualToString:@"基本資料"] 
		|| [cell.textLabel.text isEqualToString:historyrecord]){
		
		cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
	}	
	else {
		cell.accessoryType=UITableViewCellAccessoryNone;		
	}
	
	//用來消除開關莫名出現
    if ([cell.textLabel.text isEqualToString:@"程式交易最佳化設定"]) {
		cell.accessoryView=nil;		
		
	}
	
	return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *title = nil;
	switch (section) {
		case 0:
			title = NSLocalizedString(@"Stock Data",@"個股資料")   ;
			break;
		case 1:
			title =NSLocalizedString(@"Indicator Setup",@"技術指標設定");
			break;
		case 2:
			title =NSLocalizedString(@"Trading System",@"交易系統");
			break;
		default:
			break;
	}
	return title;
}


//Table 表格行選定
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	
	switch (indexPath.section) {
		case 0:{
			//基本資料
			if (indexPath.row==0){
			
			}			
			//歷史價格明細
			if (indexPath.row==0) {
				
                his=[[HistoryPriceRecord alloc] initWithTargetSymbol:stockdata];
				his.delegate=self;
				
                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
                     
                    popController = [[UIPopoverController alloc] initWithContentViewController:his];
                    
                    his.delegate_UIPopoverController= popController;
                    
                      popController.popoverContentSize = CGSizeMake(320,460);
                     [ popController presentPopoverFromBarButtonItem:barbuttonitem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];  
                    
                    
                    ////如果點選次圖 則將垂直顯示的走勢圖設定的浮動圖銷失           
                    NSLog(@"Get_popController_info_next");
                    [(AppDelegate * )AppleDeglate Get_popController_info_next:popController];                    
                    
                       
                    
                    
                    
                    
                }               
                else{
                    [self presentModalViewController:his animated:YES];     
                }
               
				 
			}
			//歷史技術指標明細
			if (indexPath.row==2) {
				
				hist =[[HistoryTechnologyRecord alloc] initWithNibName:nil bundle:nil];
				hist.delegate=self;
				[self presentModalViewController:hist animated:YES];
				
			}
			break;
		}
		case 1:{
			//LF
			if (indexPath.row==1){
				//標記:判斷是MESA或LF
                NSString *DisplayName;
                DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
                NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];    
                
                if ([DisplayName_array count]>=3) {
                    if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
                        //MESA
                        
                        mesas=[[MESASetUP alloc] initWithNibName:nil bundle:nil];
                        mesas.delegate=self;
                        
                        
                        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
                            popController = [[UIPopoverController alloc] initWithContentViewController:mesas];
                            
                            mesas.delegate_UIPopoverController=popController;
                            
                            popController.popoverContentSize = CGSizeMake(320,460);
                            [popController presentPopoverFromBarButtonItem:barbuttonitem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];   
                            
                            if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ) {
                                //垂直
                                
                                
                            }                        
                            ////如果點選次圖 則將垂直顯示的走勢圖設定的浮動圖銷失           
                            [(AppDelegate * )AppleDeglate  Get_popController_info_next: popController];                    
                            
                        }               
                        else{
                            [self presentModalViewController:mesas animated:YES];   
                        }                      
                        
                        
                    }
                    else{
                        //開始LF
                        
                        
                        
                        NSLog(@"LF");
                        lfs=[[LFSetUP alloc] initWithNibName:nil bundle:nil];
                        lfs.delegate=self;
                        
                        
                        
                        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
                            popController = [[UIPopoverController alloc] initWithContentViewController:lfs];
                            
                            lfs.delegate_UIPopoverController=popController;
                            
                            popController.popoverContentSize = CGSizeMake(320,460);
                            [popController presentPopoverFromBarButtonItem:barbuttonitem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];  
                            
                            if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ) {
                                //垂直
                                
                                
                            }                        
                            else{
                                
                            }
                            ////如果點選次圖 則將垂直顯示的走勢圖設定的浮動圖銷失           
                            [(AppDelegate * )AppleDeglate  Get_popController_info_next: popController];                    
                            
                        }               
                        else{
                            [self presentModalViewController:lfs animated:YES];	    
                        }
                        
                        
                        
                        
                        
                        
                    }
                }
                
                
                
                              
			}				
							
			
			
			//移動均線
			if (indexPath.row==2){
				NSLog(@"移動均線");
				mvs =[[MovingAverageSetUp alloc] initWithNibName:nil bundle:nil];
				mvs.delegate=self;
								
				
                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
                     popController = [[UIPopoverController alloc] initWithContentViewController:mvs];
                    
                    mvs.delegate_UIPopoverController=popController;
                    
                    popController.popoverContentSize = CGSizeMake(320,460);
                    [popController presentPopoverFromBarButtonItem:barbuttonitem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];    
                    
                   if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ){
                        //垂直
                                           
                        
                        
                    }                        
                    ////如果點選次圖 則將垂直顯示的走勢圖設定的浮動圖銷失           
                    [(AppDelegate * )AppleDeglate  Get_popController_info_next: popController];                     
                }               
                else{
                   [self presentModalViewController:mvs animated:YES];    
                }
                
                
                
				
			}				
			//KD指標
			if (indexPath.row==3){
				NSLog(@"KD指標");				
				kds=[[KDSetUP alloc] initWithNibName:nil bundle:nil];
				kds.delegate=self;
								
				
                
                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
                    popController = [[UIPopoverController alloc] initWithContentViewController:kds];
                    
                    kds.delegate_UIPopoverController=popController;
                    
                    popController.popoverContentSize = CGSizeMake(320,460);
                    [popController presentPopoverFromBarButtonItem:barbuttonitem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];  
                    
                   if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ){
                        //垂直
                       
                        
                    }                        
                    ////如果點選次圖 則將垂直顯示的走勢圖設定的浮動圖銷失           
                    [(AppDelegate * )AppleDeglate  Get_popController_info_next: popController];                    
                }               
                else{
                   [self presentModalViewController:kds animated:YES];	   
                }                
                
                
                
                
				
			}				
			//成交量
			if (indexPath.row==4){
				NSLog(@"成交量");
				vols=[[VolumeSetUP alloc] initWithNibName:nil bundle:nil];
				vols.delegate=self;
			
                
                
                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
                    popController = [[UIPopoverController alloc] initWithContentViewController:vols];
                    
                    vols.delegate_UIPopoverController=popController;
                    
                    popController.popoverContentSize = CGSizeMake(320,460);
                    [popController presentPopoverFromBarButtonItem:barbuttonitem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];   
                    
                    if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ) {
                        //垂直
                      
                        
                    }                        
                    ////如果點選次圖 則將垂直顯示的走勢圖設定的浮動圖銷失           
                    [(AppDelegate * )AppleDeglate  Get_popController_info_next: popController];                    
                    
                    
                }               
                else{
                    [self presentModalViewController:vols animated:YES];   
                }                           
                
                
			}	
			
			 						
			
			break;
			
			
		}
		case 2:{
			if (indexPath.row==1) {
				//程式交易買賣線損益報告
			 	[stockdata Caluate_TradeSystem:@"S1"];  //單一參數的計算				
				 
				
                
                
                
				trasd=[[TradeSystemDetailRecord alloc] initWithTargetSymbol:stockdata];
				trasd.delegate=self;
				//計算交易系統損益買賣點資料
				
				
				
                
                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
                     popController = [[UIPopoverController alloc] initWithContentViewController:trasd];
                    
                    trasd.delegate_UIPopoverController=popController;
                    
                    popController.popoverContentSize = CGSizeMake(320,460);
                    [popController presentPopoverFromBarButtonItem:barbuttonitem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
                    
                    if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ) {
                        //垂直
                       
                        
                    }                        
                    ////如果點選次圖 則將垂直顯示的走勢圖設定的浮動圖銷失           
                    [(AppDelegate * )AppleDeglate  Get_popController_info_next: popController];                    
                    
                    
                }               
                else{
                   [self presentModalViewController:trasd animated:YES];
                }                           
                
                
			}			
			if (indexPath.row==2) {
				[stockdata Caluate_TradeSystem:@"M2"]; //多參數的計算 但是指示顯式檢查用並不需要儲存 且記憶體部刪除
				
				
				//計算交易系統
			 	traopt=[[TradeSystemOptimized alloc] initWithTargetSymbol:stockdata];
				traopt.delegate=self;
				//計算交易系統損益買賣點資料
				
				
                
                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
                    popController = [[UIPopoverController alloc] initWithContentViewController:traopt];
                    
                    traopt.delegate_UIPopoverController=popController;
                    
                    popController.popoverContentSize = CGSizeMake(320,460);
                    [popController presentPopoverFromBarButtonItem:barbuttonitem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
                    if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ) {
                        //垂直
                      
                        
                    }                        
                    ////如果點選次圖 則將垂直顯示的走勢圖設定的浮動圖銷失           
                    [(AppDelegate * )AppleDeglate  Get_popController_info_next: popController];                    
                    
                    
                }               
                else{
                   [self presentModalViewController:traopt animated:YES];
                }                        
                
                
                
			}	
 
			if (indexPath.row==3) {
				//程式交易最佳化設定
			 	tsosetp=[[TSO_Setup alloc] init];
				tsosetp.delegate=self;
				//計算交易系統損益買賣點資料
			
				
                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
                    popController = [[UIPopoverController alloc] initWithContentViewController:tsosetp];
                    
                   tsosetp.delegate_UIPopoverController=popController;
                    
                    popController.popoverContentSize = CGSizeMake(320,460);
                    [popController presentPopoverFromBarButtonItem:barbuttonitem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];    
                    
                    if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ){
                        //垂直
                     
                        
                    }                        
                    ////如果點選次圖 則將垂直顯示的走勢圖設定的浮動圖銷失           
                    [(AppDelegate * )AppleDeglate  Get_popController_info_next: popController];                    
                    
                    
                }               
                else{
                   	[self presentModalViewController:tsosetp animated:YES];  
                }                        
                
                
                
                
			}					
			
			
			break;
		}
		 
			
			
			
			
		default:
			break;
	}
	
	
	
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
	
    NSString *exchanges=@"";
    
    //標記:是否移除交易所碼        
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
    
    if ([[prefs objectForKey:@"isRemoveExchangeCode"] boolValue]==YES) {
        //字串分割
        NSArray *code_exchange_Array = [stockdata.symbol componentsSeparatedByString:@"."];
        if ([code_exchange_Array count]==2) {
            // [code_exchange_Array objectAtIndex:0]    
            //標記:檢視第一個字串是否等於某這字
            
            NSString *temp = @"^";            
            if([temp characterAtIndex:0] == [[code_exchange_Array objectAtIndex:0] characterAtIndex:0] ){
                exchanges=@"Index";          
            }            
            else{
                ExchangeClass *tempe;
                tempe=[[ExchangeClass alloc] init];
                exchanges=  [tempe Get_exchange_fullname:[code_exchange_Array objectAtIndex:1]];
                [tempe release];             
                
            }
        }
        else{
            //  stockdata.symbol  
            NSString *temp = @"^";            
            
            if([temp characterAtIndex:0] == [[code_exchange_Array objectAtIndex:0] characterAtIndex:0] ){
                exchanges=@"Index";          
            }            
            else{
                
                ExchangeClass *tempe;
                tempe=[[ExchangeClass alloc] init];
                exchanges=  [tempe Get_exchange_fullname:[code_exchange_Array objectAtIndex:0]];
                [tempe release];             
                
            }
            
            
            
        }
        
    }
    else {
        //stockdata.symbol  ;
    }                
    NSString *title = nil;
	switch (section) {
		case 0:
			title = @"";
			break;
		case 1:
			title = exchanges;//設定交易所
			break;
		case 2:
			title = @"設定買賣訊號與交易系統";
			break;
		default:
			break;
	}
	return title;	
	
	
}
 
 
#pragma mark -
#pragma mark  按鈕轉換
-(void)switchChange:(id) sender{
	
	UISwitch *onoff = (UISwitch *) sender;	
	
	
	switch (onoff.tag) {
		case 100:{
			//搜尋是否要使用名稱
			NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
			[prefs setObject:[NSNumber numberWithBool: onoff.on]  forKey:@"isSowIndicatorNumber"];
			[prefs synchronize];	//將記憶體中的資料存到硬體上 儲存指令 			 
			
			break;
		}
		 
			
		default:
			break;
	}
	
	
	 
	
	
}


#pragma mark -
#pragma mark  回歸Finish
- (void)MESASetUP_DidFinish:(MESASetUP *)controller{
	[self dismissModalViewControllerAnimated:YES];
}

- (void)LFSetUP_DidFinish:(LFSetUP *)controller{
 [self dismissModalViewControllerAnimated:YES];
}

- (void)VolumeSetUP_DidFinish:(VolumeSetUP *)controller{
 [self dismissModalViewControllerAnimated:YES];
}

- (void)KDSetUP_DidFinish:(KDSetUP *)controller{
  [self dismissModalViewControllerAnimated:YES];
}
- (void)MovingAverageSetUp_DidFinish:(MovingAverageSetUp *)controller{
  [self dismissModalViewControllerAnimated:YES];
}


- (void)TSO_SetupDidFinish:(TSO_Setup *)controller{
	[self dismissModalViewControllerAnimated:YES];	
	
}

- (void)HistoryPriceRecordDidFinish:(HistoryPriceRecord *)controller{
	[self dismissModalViewControllerAnimated:YES];
}
- (void)HistoryTechnologyRecordDidFinish:(HistoryTechnologyRecord *)controller{
    [self dismissModalViewControllerAnimated:YES];	
	
}

- (void)TradeSystemDetailRecordDidFinish:(TradeSystemDetailRecord *)controller{
   [self dismissModalViewControllerAnimated:YES];
}
- (void)TradeSystemOptimizedRecordDidFinish:(TradeSystemOptimized *)controller{
  [self dismissModalViewControllerAnimated:YES];
}


#pragma mark -
#pragma mark  退出至上一層
-(void)slideOut{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        //將UIPopoverController 消失
        [delegate_UIPopoverController dismissPopoverAnimated:YES];
                 
    }
    else{
        
            
    }
    
    [self.delegate flipsideViewControllerDidFinish:self]; 
   
	
    
}

#pragma mark -
#pragma mark  其他
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
 
- (void)dealloc {	
	 
	[myTable release];
	[StockInformation_0 release];
	[TechIndicator_1 release];
	[TradeSystem_2 release];
	[super dealloc];
}


@end
